package com.itheima.day10;

import com.itheima.util.BallUtil;

import javax.naming.PartialResultException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.TreeMap;
import java.util.TreeSet;

/*
双色球

1_ 5000注不允许重复
2_ 蓝色球 连号最多出现连三，连四及以上不允许出现
3_ 统计5000个号中号码10,20,30分别出现的次数
4_ 5000个号码中，哪个号码出现的次数最多？

 */
public class Test02 {

    public static void main(String[] args) {
        /*int[] all = BallUtil.getAll();
        System.out.println(Arrays.toString(all));*/
        TreeSet<int[]> set = new TreeSet<>(
                (o1,o2)->{
                    int result=0;
                    for (int i=0;i<6;i++) {
                        result=result==0? o1[i] - o2[i]:result;
                    }
                    return result;

                }
        );
        while (set.size()<5000) {
            int[] all = BallUtil.getAll();
            set.add(all);
        }

        set.forEach(arr-> System.out.println(Arrays.toString(arr)));

        int count10=0;
        int count20=0;
        int count30=0;
        for (int[] arr : set) {
            for (int j=0;j<6;j++) {
                if(arr[j]==10){
                    count10++;
                }
                if(arr[j]==20){
                    count20++;
                }
                if(arr[j]==30){
                    count30++;
                }
            }
        }
        System.out.println("蓝球中10出现了"+count10);
        System.out.println("蓝球中20出现了"+count20);
        System.out.println("蓝球中30出现了"+count30);


        TreeMap<Integer, Integer> countMap = new TreeMap<>();
        for (int[] arr : set) {
            for (int j=0;j<6;j++) {
                int ball = arr[j];
                if(countMap.containsKey(ball)){
                    countMap.put(ball,countMap.get(ball)+1);
                }else {
                    countMap.put(ball,1);
                }
            }
        }
        countMap.forEach((k,v)-> System.out.println(k+"在蓝球中出现了"+v+"次"));
        TreeSet<Ball> balls = new TreeSet<>();
        countMap.forEach((k,v)->balls.add(new Ball(k,v)));

        for (Ball ball : balls) {
            System.out.println(ball.ball+"出现了"+ball.count);
        }
    }
}
class  Ball implements Comparable<Ball>{
    int ball;
     int count;

    public Ball(int ball, int count) {
        this.ball = ball;
        this.count = count;
    }

    @Override
    public int compareTo(Ball o) {
        return o.count-this.count==0?this.ball-o.ball:o.count-this.count;
    }

    @Override
    public String toString() {
        return "Ball{" +
                "ball=" + ball +
                ", count=" + count +
                '}';
    }
}